package com.example.rouroudate.util

import android.app.Application

object ApplicationUtils {
    private const val TAG = "ApplicationUtils"

    val instance: Application by lazy {
        val result = kotlin.runCatching {
            val activityThreadClass = Class.forName("android.app.ActivityThread")
            val sCurrentActivityThreadField = activityThreadClass.getDeclaredField("sCurrentActivityThread");
            sCurrentActivityThreadField.isAccessible = true
            val thread = sCurrentActivityThreadField[null]
            activityThreadClass.getMethod("getApplication").invoke(thread) as Application
        }
        if (result.exceptionOrNull() != null) {
            throw result.exceptionOrNull()!!
        }
        result.getOrNull()!!
    }
}
